package com.ppmall.common;

import java.util.HashMap;
import java.util.Map;

public class R {

    private Integer code;
    private String msg;
    private Map< String, Object> extend = new HashMap<>();

    public static Integer CODE_OK = 20000;
    public static Integer CODE_ERROR = 20001;

    public static String MSG_OK = "OK";
    public static String MSG_EEROR = "ERROR";

    private R() {}

    public static R ok() {
        return new R().code(CODE_OK).msg(MSG_OK);
    }

    public static R error() {
        return new R().code(CODE_ERROR).msg(MSG_EEROR);
    }

    public R data(String key, Object value) {
        extend.put(key, value);
        return this;
    }

    public R code(Integer code) {
        this.code = code;
        return this;
    }

    public R msg(String msg) {
        this.msg = msg;
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map< String, Object> getExtend() {
        return extend;
    }

    public void setExtend(Map< String, Object> extend) {
        this.extend = extend;
    }

    @Override
    public String toString() {
        return "R{" +
            "code=" + code +
            ", msg='" + msg + '\'' +
            ", extend=" + extend +
            '}';
        }
}
